﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LEET.LEETCommon.Model;
using LEET.CommonInterfaces.TestControls;
using LEET.LEETCommon.WidgetLookup;
using System.Windows.Automation;
using Compiled_Tests;

namespace ExpandCollapse
{
    public class ExpndColpsInstruction : Instruction
    {
        String element;
        bool expand;
        public ExpndColpsInstruction(String[] args) : base(args)
        {
            element = args[2];
            expand = (args[3].Trim() == "Expanded");
        }

        public static IAutomationActionResult StaticCall(IBox box, String element, bool expand)
        {
            AutomationElement e = WidgetFinder.Find(element, box.RootElement);
            Object obj;
            e.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out obj);
            ExpandCollapsePattern pattern = obj as ExpandCollapsePattern;
            if (pattern != null)
            {
                if (expand)
                    pattern.Expand();
                else
                    pattern.Collapse();
            }
            return new AutomationActionResult();
        }

        public override String RenderStaticCall()
        {
            return "ExpandCollapse.ExpndColpsInstruction.StaticCall(Box, \""+element+"\", "+expand.ToString()+")";
        }

        public override string PlainText()
        {
            return ((expand) ? "Expands" : "Collapses") + element;
        }
    }
}
